<%--
  Created by IntelliJ IDEA.
  User: gqy
  Date: 2021/10/9
  Time: 15:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>登录</title>
    <span style="font-size: 10px;color: red">
        ${loginMsg}
    </span>
    <script src="${pageContext.request.contextPath}/js/jquery-3.6.0.min.js"></script>
    <link href="${pageContext.request.contextPath}/css/login/login.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jsencrypt/bin/jsencrypt.min.js"></script>

    <style>
        .username-msg,.password-msg{
            font-size: 10px;
            color: red;
        }
    </style>
</head>
<body>
<div id="main">
    <div class="login-wrap">
        <div id="signin" class="rl-modal">
            <div class="rl-modal-header">
                <h1>
                    <span class="active-title"><a href="${pageContext.request.contextPath}/login/login.jsp" style="list-style: none;text-decoration:none;">账号登录</a></span>
                    <span class="xa-showPhoneSignin" rel="stylesheet"><a href="${pageContext.request.contextPath}/login/code.jsp" style="list-style: none;text-decoration:none;">验证码登录</a></span>
                </h1>
                <span style="font-size: 10px;color: red">${loginMsg1}</span>
            </div>
            <div class="rl-modal-body js-loginWarp">
                <div class="clearfix">
                    <form action="${pageContext.request.contextPath}/login" id="signup-from" method="post">
                        <div class="rlf-group pr">
                            <input type="text" value maxlength="37" class="ipt usertel" placeholder="请输入手机号码" name="consumerTel">
                            <p class="rlf-tip-wrap userTel-msg"></p>
                        </div>
                        <div class="rlf-group pr">
                            <input type="hidden" name="consumerPassword" id="password">
                            <input type="password"
                                   class="ipt password"
                                   placeholder="请输入密码" maxlength="20">
                            <p class="rlf-tip-wap password-msg"></p>
                        </div>
                        <div class="rlf-group clearfix">
                            <input type="button" value="登录"
                                   class="moco-btn moco-btn-red moco-btn-lg btn-full">
                        </div>
                    </form>
                </div>
            </div>
            <div class="rl-model-footer">
                <div class="pop-login-signup-box clearfix">
                    <span class="xa-showSignup"><a href="${pageContext.request.contextPath}/login/register.jsp" style="list-style: none;text-decoration:none;">快速注册</a></span>
                </div>
            </div>

        </div>
    </div>
</div>


<script>
    //验证手机号码
    document.querySelector(".usertel").onblur = checkUserTel;
    function  checkUserTel(){
        var userTel = document.querySelector(".userTel").value;
        if(userTel == "" || userTel == null){// 是否为空
            //(3)消息提示
            document.querySelector(".userTel-msg").innerText = "手机号码不能为空";
            return false;
        }else if( !/^(0|86|17951)?1[0-9]{10}$/.test(userTel) ){
            document.querySelector(".userTel-msg").innerText = "不是有效的手机号码";
            return false;
        }else{
            document.querySelector(".userTel-msg").innerText = "";
            return true;
        }
    }
    //验证密码
    document.querySelector(".password").onblur = checkPassword;
    function  checkPassword(){
        var password = document.querySelector(".password").value;
        if(password == "" || password == null){// 是否为空
            //(3)消息提示
            document.querySelector(".password-msg").innerText = "密码不能为空";
            return false;
        }else if( !/^[a-zA-Z0-9]\w{5,19}$/.test(password) ){
            document.querySelector(".password-msg").innerText = "密码不正确";
            return false;
        }else{
            document.querySelector(".password-msg").innerText = "";
            return true;
        }
    }
    var PUBLIC_KEY = '';
    $(".moco-btn").click(function () {
        $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/publickey1",
            dataType: 'json',
            success: function (result) {
                PUBLIC_KEY = result.data; //获取公钥

                var encrypt = new JSEncrypt()
                encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
                var password = $(".password").val();
                var encrypted = encrypt.encrypt(password);
                // $(".password").val(encrypted);
                console.log('公钥:%o', PUBLIC_KEY);
                console.log('密码:%o', password)
                console.log('加密后数据:%o', encrypted);
                $('#password').val(encrypted);

                if (checkUserTel()  && checkPassword() ) {
                    $("#signup-from").submit();
                };
            }

        });
    });

</script>
</body>
</html>
